﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MyWPF.Models.PC.Disk
{
    public class DiskHelper : IDisk
    {
        public DiskContext GetDiskInfo(int Precision = 2)
        {
            DiskContext Disk = new DiskContext()
            {
                Name = new List<string>(),
                Volume = new List<double>(),
                UsedVolume = new List<double>(),
                VolumeUsage = new List<double>()
            };
            DriveInfo[] drives = DriveInfo.GetDrives();
            foreach (DriveInfo drive in drives)
            {
                if (drive.IsReady)
                {
                    double Volume = (double)drive.TotalSize / 1024 / 1024 / 1024;
                    double UsedVolume = (double)(drive.TotalSize - drive.AvailableFreeSpace) / 1024 / 1024 / 1024;
                    Disk.Name.Add(drive.Name.Substring(0,1));
                    Disk.Volume.Add(Math.Round(Volume,Precision));
                    Disk.UsedVolume.Add(Math.Round(UsedVolume,Precision));
                    Disk.VolumeUsage.Add(Math.Round(UsedVolume / Volume * 100, Precision));
                }
            }

            return Disk;
        }
    }
}
